package lab03.test04;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test04 {
    public static void main(String[] args) {

        //在D盘下创建文件夹source和target
        // 在source文件夹中存放“hello.txt”

        // 使用字节输出流写入文件夹target下

        String source = "D:\\java实验\\lab03test04.txt";
        String target = "G:\\lab03test04.txt";
        //使用字节输入流读入文件，
        FileOutputStream fileOutputStream = null;
        FileInputStream fileInputStream = null;

        try {
            fileInputStream = new FileInputStream(source);
            fileOutputStream = new FileOutputStream(target);
            int data;

            while ((data = fileInputStream.read()) != -1) {
                fileOutputStream.write(data);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
